package com.hbnu.serializable;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author kittychen
 * @since 2025-10-14 11:14
 */
public class SerializableTest2 {

    public static void main(String[] args) {
        String path = "E:" + File.separator + "2309" + File.separator + "object.txt";
        File file = new File(path);

        ObjectInputStream objectInputStream = null;

        try {
            objectInputStream = new ObjectInputStream(new FileInputStream(file));

            Person zhangsan = (Person) objectInputStream.readObject();

            System.out.println(zhangsan.getName() + "-->" + zhangsan.getAge());
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (objectInputStream != null) {
                    objectInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
